package com.snopy.jvm.heap;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author snopy
 * @version 1.0.0
 * @classname DemoOOM
 * @description
 * 导出OOM时的堆信息
 * -XX:+HeapDumpOnOutOfMemoryError
 * @email 77912204@qq.com
 * @date 2022/07/04 14:11
 */
@Slf4j
public class DemoOOM {

    public static void main(String[] args) {
        int i = 0;
        try {
            String a = "hello";
            List<String> list = new ArrayList<>();
            while (true){
                list.add(a);
                a = a+a;
                i++;
            }
        }catch (OutOfMemoryError e){
            e.printStackTrace();
            log.error("excute conunt:{}",i);
        }
    }
}
